<template>
  <Form
    ref="tempCheckForm"
    :model="form"
    :rules="rules"
    @keydown.enter.native="handleSubmit"
    inline
    :label-width="85">
    <FormItem prop="ctime" style="width: 250px" label="申请日期：">
      <DatePicker v-model="form.ctime" type="date" placeholder="请选择申请日期"></DatePicker>
    </FormItem>
    <FormItem prop="state" label="审核状态：" style="width: 250px;">
      <Select v-model="form.state" placeholder="请选择审核状态" clearable>
        <Option value="all">
          全部
        </Option>
        <Option value="0">
          未审核
        </Option>
        <Option value="1">
          审核通过
        </Option>
        <Option value="2">
          未通过
        </Option>
      </Select>
    </FormItem>
    <FormItem style="float: right;">
      <Button @click="handleSubmit" icon="md-search" type="primary">
        搜索
      </Button>
    </FormItem>
  </Form>
</template>
<script>
import {
  mapState,
  mapActions,
  mapMutations
} from 'vuex'
export default {
  name: 'TempCheckForm',
  props: {
    stateRules: {
      type: Array,
      default: () => {
        return []
      }
    },
    ctimeRules: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      form: {
        ctime: '',
        state: 'all'
      }
    }
  },
  computed: {
    rules () {
      return {
        ctime: this.ctimeRules,
        state: this.stateRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.tempCheckForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            ctime: this.form.ctime ? this.$moment(this.form.ctime).format('YYYY-MM-DD') : '',
            state: this.form.state && this.form.state !== 'all' ? parseInt(this.form.state) : ''
          })
        }
      })
    }
  }
}
</script>
